#include <iostream>
using namespace std;
int run_fn(int fn(int a, int b))
{
    return fn(1, 2);
}
int sum(int a, int b)
{
    return a + b;
}
int main()
{
    // 函数作为参数实际上传递的是指向函数的指针
    int (*q)(int, int) = sum;
    cout << run_fn(sum) << endl;
    cout << run_fn(q) << endl;

    // 创建一个lambda表达式
    int (*lambda1)(int, int) = [](int a, int b) -> int { return a + b; };
    // 使用auto 推断lambda的类型
    auto lambda = [](int a, int b) -> int { return a + b; };
    cout << "lambda's result is " << run_fn(lambda) << endl;
    // 当返回值类型可以推导时，省略返回值类型【-> int】
    auto lambda2 = [](int a, int b){ return a + b; };
    cout << "lambda2's result is " << run_fn(lambda2) << endl;
    // 调用裸lambda函数
    cout << run_fn([](int a, int b) -> int { return a + b; })<< endl;
    return 0;
}
